package com.atguigu.tingshu.handler;

import com.atguigu.tingshu.model.CDCEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import top.javatool.canal.client.annotation.CanalTable;
import top.javatool.canal.client.handler.EntryHandler;
@Component
@Slf4j
@CanalTable("user_info")
public class UserCdcHandler implements EntryHandler<CDCEntity> {
    @Autowired
    private RedisTemplate redisTemplate;
    @Override
    public void insert(CDCEntity cdcEntity) {
        EntryHandler.super.insert(cdcEntity);
    }

    @Override
    public void update(CDCEntity before, CDCEntity after) {
        log.info("监控到数据修改"+after.getId());

        try {
            redisTemplate.delete("album_info"+after.getId());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        EntryHandler.super.update(before, after);
    }

    @Override
    public void delete(CDCEntity cdcEntity) {
        log.info("监控到数据删除"+cdcEntity.getId());
        EntryHandler.super.delete(cdcEntity);
    }
}
